<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css" type="text/css" media="screen">
<link rel="stylesheet" href="../../print.css" type="text/css" media="print">
<meta content="YAML,org.as3yaml.YAML,DEFAULT_MAPPING_TAG,DEFAULT_SCALAR_TAG,DEFAULT_SEQUENCE_TAG,decode,dump,encode,load" name="keywords">
<title>org.as3yaml.YAML</title>
</head>
<body>
<script type="text/javascript" language="javascript" src="../../asdoc.js"></script><script type="text/javascript" language="javascript" src="../../cookies.js"></script><script type="text/javascript" language="javascript">
<!--
				asdocTitle = 'YAML - AS3YAML Docs';
				var baseRef = '../../';
				window.onload = configPage;
			--></script>
<table style="display:none" id="titleTable" cellspacing="0" cellpadding="0" class="titleTable">
<tr>
<td align="left" class="titleTableTitle">AS3YAML Docs</td><td align="right" class="titleTableTopNav"><a onclick="loadClassListFrame('../../all-classes.html')" href="../../package-summary.html">All&nbsp;Packages</a>&nbsp;|&nbsp;<a onclick="loadClassListFrame('../../all-classes.html')" href="../../class-summary.html">All&nbsp;Classes</a>&nbsp;|&nbsp;<a onclick="loadClassListFrame('../../index-list.html')" href="../../all-index-A.html">Index</a>&nbsp;|&nbsp;<a href="../../index.html?org/as3yaml/YAML.html&amp;org/as3yaml/class-list.html" id="framesLink1">Frames</a><a onclick="parent.location=document.location" href="" style="display:none" id="noFramesLink1">No&nbsp;Frames</a></td><td rowspan="3" align="right" class="titleTableLogo"><img alt="Adobe Logo" title="Adobe Logo" class="logoImage" src="../../images/logo.jpg"></td>
</tr>
<tr class="titleTableRow2">
<td align="left" id="subTitle" class="titleTableSubTitle">Class&nbsp;YAML</td><td align="right" id="subNav" class="titleTableSubNav"><a href="#methodSummary">Methods</a>&nbsp;| <a href="#constantSummary">Constants</a></td>
</tr>
<tr class="titleTableRow3">
<td colspan="2">&nbsp;</td>
</tr>
</table>
<script type="text/javascript" language="javascript">
<!--
if (!isEclipse() || window.name != ECLIPSE_FRAME_NAME) {titleBar_setSubTitle("Class YAML"); titleBar_setSubNav(true,false,false,false,false,false,true,false,false,false,false,false,false,false);}
--></script>
<div class="MainContent">
<table cellspacing="0" cellpadding="0" class="classHeaderTable">
<tr>
<td class="classHeaderTableLabel">Package</td><td><a onclick="javascript:loadClassListFrame('class-list.html')" href="package-detail.html">org.as3yaml</a></td>
</tr>
<tr>
<td class="classHeaderTableLabel">Class</td><td class="classSignature">public class YAML</td>
</tr>
</table>
<p></p>
 
 This all static class provides methods for encoding and decoding YAML.  The primary methods are YAML.encode()
 and YAML.decode().  YAML.load() and YAML.Dump() are for advanced users.
 
 <p></p>
<br>
<hr>
</div>
<a name="methodSummary"></a>
<div class="summarySection">
<div class="summaryTableTitle">Public Methods</div>
<table id="summaryTableMethod" class="summaryTable " cellpadding="3" cellspacing="0">
<tr>
<th>&nbsp;</th><th colspan="2">Method</th><th class="summaryTableOwnerCol">Defined&nbsp;by</th>
</tr>
<tr class="">
<td class="summaryTablePaddingCol">&nbsp;</td><td class="summaryTableInheritanceCol">&nbsp;</td><td class="summaryTableSignatureCol">
<div class="summarySignature">
<a class="signatureLink" href="#decode()">decode</a>(yaml:String):Object</div>
<div class="summaryTableDescription">[static]
     
     Takes a YAML string an converts it to an ActionScript Object.</div>
</td><td class="summaryTableOwnerCol">YAML</td>
</tr>
<tr class="">
<td class="summaryTablePaddingCol">&nbsp;</td><td class="summaryTableInheritanceCol">&nbsp;</td><td class="summaryTableSignatureCol">
<div class="summarySignature">
<a class="signatureLink" href="#dump()">dump</a>(data:List, output:StringWriter, fact:YAMLFactory, cfg:YAMLConfig):void</div>
<div class="summaryTableDescription">[static]</div>
</td><td class="summaryTableOwnerCol">YAML</td>
</tr>
<tr class="">
<td class="summaryTablePaddingCol">&nbsp;</td><td class="summaryTableInheritanceCol">&nbsp;</td><td class="summaryTableSignatureCol">
<div class="summarySignature">
<a class="signatureLink" href="#encode()">encode</a>(obj:Object):String</div>
<div class="summaryTableDescription">[static]
  Takes an object and converts it to a YAML encoded string.</div>
</td><td class="summaryTableOwnerCol">YAML</td>
</tr>
<tr class="">
<td class="summaryTablePaddingCol">&nbsp;</td><td class="summaryTableInheritanceCol">&nbsp;</td><td class="summaryTableSignatureCol">
<div class="summarySignature">
<a class="signatureLink" href="#load()">load</a>(io:String, fact:YAMLFactory, cfg:YAMLConfig):Object</div>
<div class="summaryTableDescription">[static]</div>
</td><td class="summaryTableOwnerCol">YAML</td>
</tr>
</table>
</div>
<a name="constantSummary"></a>
<div class="summarySection">
<div class="summaryTableTitle">Public Constants</div>
<table id="summaryTableConstant" class="summaryTable " cellpadding="3" cellspacing="0">
<tr>
<th>&nbsp;</th><th colspan="2">Constant</th><th class="summaryTableOwnerCol">Defined&nbsp;by</th>
</tr>
<tr class="">
<td class="summaryTablePaddingCol">&nbsp;</td><td class="summaryTableInheritanceCol">&nbsp;</td><td class="summaryTableSignatureCol"><a class="signatureLink" href="#DEFAULT_MAPPING_TAG">DEFAULT_MAPPING_TAG</a> : String = "tag:yaml.org,2002:map"<div class="summaryTableDescription">[static]</div>
</td><td class="summaryTableOwnerCol">YAML</td>
</tr>
<tr class="">
<td class="summaryTablePaddingCol">&nbsp;</td><td class="summaryTableInheritanceCol">&nbsp;</td><td class="summaryTableSignatureCol"><a class="signatureLink" href="#DEFAULT_SCALAR_TAG">DEFAULT_SCALAR_TAG</a> : String = "tag:yaml.org,2002:str"<div class="summaryTableDescription">[static]</div>
</td><td class="summaryTableOwnerCol">YAML</td>
</tr>
<tr class="">
<td class="summaryTablePaddingCol">&nbsp;</td><td class="summaryTableInheritanceCol">&nbsp;</td><td class="summaryTableSignatureCol"><a class="signatureLink" href="#DEFAULT_SEQUENCE_TAG">DEFAULT_SEQUENCE_TAG</a> : String = "tag:yaml.org,2002:seq"<div class="summaryTableDescription">[static]</div>
</td><td class="summaryTableOwnerCol">YAML</td>
</tr>
</table>
</div>
<script type="text/javascript" language="javascript">
<!--
showHideInherited();
--></script>
<div class="MainContent">
<a name="methodDetail"></a>
<div class="detailSectionHeader">Method detail</div>
<a name="decode()"></a>
<table cellspacing="0" cellpadding="0" class="detailHeader">
<tr>
<td class="detailHeaderName">decode</td><td class="detailHeaderParens">()</td><td class="detailHeaderType">method</td>
</tr>
</table>
<div class="detailBody">
<code>public static function decode(yaml:String):Object</code><p>
     
     Takes a YAML string an converts it to an ActionScript Object.
  
  </p><span class="label">Parameters</span>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20px"></td><td><code><span class="label">yaml</span>:String</code> &mdash; a YAML string.
     </td>
</tr>
</table>
<p></p>
<span class="label">Returns</span>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"></td><td><code>Object</code> &mdash; an actionscript object. The object type will depend on the YAML. 
                The cost common return types are Dictionary or Array.
     
     </td>
</tr>
</table>
<br>
<span class="label">Example</span>
<br>
  
  With the following YAML is stored in a file called myYaml.yaml
  
  <div class='listing'><pre>
  
  ---
  Date: 2001-11-23 15:03:17 -5
  User: ed
  Fatal:
    Unknown variable "bar"
  Stack:
    - file: TopClass.py
      line: 23
      code: |
        x = MoreObject("345\n")
    - file: MoreClass.py
      line: 58
      code: |-
        foo = bar 
       
  </pre></div>
  
  You can load then load the YAML and decode it as follows.
  
  <div class='listing'><pre>
   public function loadYaml() : void
   {
   var loader : URLLoader =  new URLLoader();
   loader.load(new URLRequest('myYaml.yaml'));
   loader.addEventListener(Event.COMPLETE, onYamlLoad);
   }
   
  public function onYamlLoad(event : Event) : void
  {
	 var yamlMap : Dictionary = YAML.decode(event.target.data) as Dictionary; // returns a Dictionary		
	 		
	 trace(yamlMap.Date);  // returns a Date object and prints: Fri Nov 23 15:03:17 GMT-0500 2001
	 trace(yamlMap.User);  // returns a String and prints: ed
	 trace(yamlMap.Fatal); // returns a String and prints: Unknown variable "bar"
	 trace(yamlMap.Stack); // returns an Array and prints: [object Dictionary],[object Dictionary]
	 trace(yamlMap.Stack[0].line);  // returns an Int and prints: 23
	 trace(yamlMap.Stack[0].code);  // returns a String and prints: x = MoreObject("345\n")      
    
  }
   </pre></div>
   
  AS3YAML defines one custom tag: !actionscript/object:path.to.Class. This tag can be used to create custom
  actionscript classes from YAML. For example, if you have the following class:
  
  <div class='listing'><pre>
  package org.as3yaml.test
  {
   [Bindable]
   public class TestActionScriptObject
   {
    public var firstname : String;
    public var lastname : String;
    public var birthday : Date;
    
   }
  }
  </pre></div>
  
  You can instruct AS3YAML to create an instance of this class as follows:
  
  <div class='listing'><pre>
  var yamlObj : TestActionScriptObject = YAML.decode("--- !actionscript/object:org.as3yaml.test.TestActionScriptObject\nfirstname: Derek\nlastname: Wischusen\nbirthday: 1979-12-25\n") as TestActionScriptObject;
  
  trace(yamlObj.firstname); // prints: Derek
  trace(yamlObj.lastname);  // prints: Wischusen
  trace(yamlObj.birthday);  // prints: Tue Dec 25 00:00:00 GMT-0500 1979
  </pre></div>
  
     <p></p>
</div>
<a name="dump()"></a>
<table cellspacing="0" cellpadding="0" class="detailHeader">
<tr>
<td class="detailHeaderName">dump</td><td class="detailHeaderParens">()</td><td class="detailHeaderType">method</td><td class="detailHeaderRule">&nbsp;</td>
</tr>
</table>
<div class="detailBody">
<code>public static function dump(data:List, output:StringWriter, fact:YAMLFactory, cfg:YAMLConfig):void</code><span class="label">Parameters</span>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20px"></td><td><code><span class="label">data</span>:List</code></td>
</tr>
<tr>
<td class="paramSpacer">&nbsp;</td>
</tr>
<tr>
<td width="20px"></td><td><code><span class="label">output</span>:StringWriter</code></td>
</tr>
<tr>
<td class="paramSpacer">&nbsp;</td>
</tr>
<tr>
<td width="20px"></td><td><code><span class="label">fact</span>:YAMLFactory</code></td>
</tr>
<tr>
<td class="paramSpacer">&nbsp;</td>
</tr>
<tr>
<td width="20px"></td><td><code><span class="label">cfg</span>:YAMLConfig</code></td>
</tr>
</table>
</div>
<a name="encode()"></a>
<table cellspacing="0" cellpadding="0" class="detailHeader">
<tr>
<td class="detailHeaderName">encode</td><td class="detailHeaderParens">()</td><td class="detailHeaderType">method</td><td class="detailHeaderRule">&nbsp;</td>
</tr>
</table>
<div class="detailBody">
<code>public static function encode(obj:Object):String</code><p>
  Takes an object and converts it to a YAML encoded string.
  
  </p><span class="label">Parameters</span>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20px"></td><td><code><span class="label">obj</span>:Object</code> &mdash; the object to be encoded as a YAML string.
  </td>
</tr>
</table>
<p></p>
<span class="label">Returns</span>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"></td><td><code>String</code> &mdash; a YAML encoded String.
  
  </td>
</tr>
</table>
<br>
<span class="label">Example</span>
<br>
  
  
  <div class='listing'><pre> 
  
  var map : Map = new HashMap();
  map.put("a","1");
  map.put("b","2");
  map.put("c","3");
  trace(YAML.encode(map));
  -->
    ---
    a: 1
    b: 2
    c: 3
  
  
  var list : Array = new Array("a","b","c");
  trace(YAML.encode(ex));
  -->
     --- 
     - a
     - b
     - c
    
  var customers : Map = new HashMap();
  var customer : Map = new HashMap();
  customers.put("customer", customer);
  customer.put("firstname", "Derek");
  customer.put("lastname", "Wischusen");
  customer.put("items", ["skis", "boots", "jacket"]);
  trace(YAML.encode(customers));
  --> 
    --- 
    customer: 
      firstname: Derek
      lastname: Wischusen
      items: 
        - skis
        - boots
        - jacket
  
  // The following is an example of encoding a custom ActionScript class.
  
  package org.as3yaml.test
  {
   [Bindable]
   public class TestActionScriptObject
   {
    public var firstname : String;
    public var lastname : String;
    public var birthday : Date;
    
   }
  }
  
  var testObj : TestActionScriptObject =  new TestActionScriptObject();
  testObj.firstname = "Derek";
  testObj.lastname = "Wischusen";
  testObj.birthday = new Date(1979, 11, 25);
  
  trace(YAML.encode(testObj));
  -->
    --- !actionscript/object:org.as3yaml.test.TestActionScriptObject
    birthday: 1979-12-25 24:00:00 -05:00
    firstname: Derek
    lastname: Wischusen
  
  </pre></div>
  
  
  
  <p></p>
</div>
<a name="load()"></a>
<table cellspacing="0" cellpadding="0" class="detailHeader">
<tr>
<td class="detailHeaderName">load</td><td class="detailHeaderParens">()</td><td class="detailHeaderType">method</td><td class="detailHeaderRule">&nbsp;</td>
</tr>
</table>
<div class="detailBody">
<code>public static function load(io:StringReader, fact:YAMLFactory, cfg:YAMLConfig):Object</code><span class="label">Parameters</span>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20px"></td><td><code><span class="label">io</span>:StringReader</code></td>
</tr>
<tr>
<td class="paramSpacer">&nbsp;</td>
</tr>
<tr>
<td width="20px"></td><td><code><span class="label">fact</span>:YAMLFactory</code></td>
</tr>
<tr>
<td class="paramSpacer">&nbsp;</td>
</tr>
<tr>
<td width="20px"></td><td><code><span class="label">cfg</span>:YAMLConfig</code></td>
</tr>
</table>
<p></p>
<span class="label">Returns</span>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"></td><td><code>Object</code></td>
</tr>
</table>
</div>
<a name="constantDetail"></a>
<div class="detailSectionHeader">Constant detail</div>
<a name="DEFAULT_MAPPING_TAG"></a>
<table cellspacing="0" cellpadding="0" class="detailHeader">
<tr>
<td class="detailHeaderName">DEFAULT_MAPPING_TAG</td><td class="detailHeaderType">constant</td>
</tr>
</table>
<div class="detailBody">
<code>public static const DEFAULT_MAPPING_TAG:String = "tag:yaml.org,2002:map"</code>
</div>
<a name="DEFAULT_SCALAR_TAG"></a>
<table cellspacing="0" cellpadding="0" class="detailHeader">
<tr>
<td class="detailHeaderName">DEFAULT_SCALAR_TAG</td><td class="detailHeaderType">constant</td><td class="detailHeaderRule">&nbsp;</td>
</tr>
</table>
<div class="detailBody">
<code>public static const DEFAULT_SCALAR_TAG:String = "tag:yaml.org,2002:str"</code>
</div>
<a name="DEFAULT_SEQUENCE_TAG"></a>
<table cellspacing="0" cellpadding="0" class="detailHeader">
<tr>
<td class="detailHeaderName">DEFAULT_SEQUENCE_TAG</td><td class="detailHeaderType">constant</td><td class="detailHeaderRule">&nbsp;</td>
</tr>
</table>
<div class="detailBody">
<code>public static const DEFAULT_SEQUENCE_TAG:String = "tag:yaml.org,2002:seq"</code>
</div>
<br>
<br>
<hr>
<br>
<p></p>
<center class="copyright"> 
</center>
</div>
</body>
</html>
<!-- -->
